package com.atguigu.tingshu.payment.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 支付结果通过的消息队列
 */
@Configuration
public class PaymentInfoRabbitConfig {

    /**
     * 支付信息交换机
     */
    @Bean("paymentInfoExchange")
    public Exchange paymentInfoExchange(){
        return ExchangeBuilder.directExchange("payment_info_exchange").build();
    }

    /**
     * 听书订单队列
     */
    @Bean("tingshuOrderQueue")
    public Queue tingshuOrderQueue(){
        return QueueBuilder.durable("tingshu_order_queue").build();
    }

    /**
     * tingshu订单绑定
     * @param paymentInfoExchange
     * @param tingshuOrderQueue
     * @return
     */
    @Bean
    public Binding albumOrderQueueBinding(@Qualifier("paymentInfoExchange") Exchange paymentInfoExchange,
                                            @Qualifier("tingshuOrderQueue") Queue tingshuOrderQueue){
        return BindingBuilder
                .bind(tingshuOrderQueue)
                .to(paymentInfoExchange)
                .with("payment.order")
                .noargs();
    }


    /**
     * account队列
     */
    @Bean("accountOrderQueue")
    public Queue accountQueue(){
        return QueueBuilder.durable("account_order_queue").build();
    }

    /**
     * account绑定
     */
    @Bean
    public Binding accountOrderQueueBinding(@Qualifier("paymentInfoExchange") Exchange paymentInfoExchange,
                                            @Qualifier("accountOrderQueue") Queue accountOrderQueue){
        return BindingBuilder
                .bind(accountOrderQueue)
                .to(paymentInfoExchange)
                .with("payment.account")
                .noargs();
    }

//    /**
//     * user队列
//     */
//    @Bean("userQueue")
//    public Queue userQueue(){
//        return QueueBuilder.durable("user_queue").build();
//    }
//
//    /**
//     * user绑定
//     */
//    public Binding userOrderPaymentBinding(@Qualifier("paymentInfoExchange") Exchange paymentInfoExchange,
//                                              @Qualifier("userQueue") Queue userQueue){
//        return BindingBuilder
//                .bind(userQueue)
//                .to(paymentInfoExchange)
//                .with("order.user")
//                .noargs();
//    }
//
//    /**
//     * order队列
//     */
//    @Bean("orderQueue")
//    public Queue orderQueue(){
//        return QueueBuilder.durable("order_queue").build();
//    }
//
//    /**
//     * order绑定
//     */
//    public Binding orderPaymentBinding(@Qualifier("paymentInfoExchange") Exchange paymentInfoExchange,
//                                           @Qualifier("orderQueue") Queue orderQueue){
//        return BindingBuilder
//                .bind(orderQueue)
//                .to(paymentInfoExchange)
//                .with("order.order")
//                .noargs();
//    }
}
